package com.itheima.tcp.socket.socketDemo2;

import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStreamWriter;
import java.net.ServerSocket;
import java.net.Socket;

public class ServiceDemo2 {
    public static void main(String[] args) throws IOException {
        ServerSocket serverSocket = new ServerSocket(10000);
        Socket socket = serverSocket.accept();

        InputStream is = socket.getInputStream();
        int b;
        while ((b = is.read()) != -1){
            System.out.print((char)b);
        }
        System.out.println();

        BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
        bufferedWriter.write(socket.getInetAddress() +"你谁呀");
        bufferedWriter.newLine();
        bufferedWriter.flush();
        bufferedWriter.close();
        is.close();
        socket.close();
        serverSocket.close();
    }
}
